<?php

// version 1.0.0

class CatalogModule extends CWebModule
{
    private $_assetsUrl;
    
    public function init()
    {
        $this->viewPath = Yii::getPathOfAlias('theme.views.modules.CatalogModule');
        $this->setImport(array(
                'catalog.models.*',
                'catalog.components.*',
        ));
        $this->registerScript();
    }

    public function beforeControllerAction($controller, $action)
    {
        if(parent::beforeControllerAction($controller, $action))
        {
            return true;
        }
        else
            return false;
    }
    
    public function registerScript(){
        // Get the url to the module assets
        $assetsUrl = $this->getAssetsUrl();

        // Register the necessary scripts
        $cs = Yii::app()->getClientScript();
//        $cs->registerCoreScript('jquery');
//        $cs->registerCoreScript('jquery.ui');
        $cs->registerScriptFile($assetsUrl.'/js/catalog.js');
    }
    

    public function getAssetsUrl()
    {
            if( $this->_assetsUrl===null )
            {
                    $assetsPath = Yii::getPathOfAlias('catalog.assets');

                    // We need to republish the assets if debug mode is enabled.
                    $this->_assetsUrl = Yii::app()->getAssetManager()->publish($assetsPath);
            }

            return $this->_assetsUrl;
    }
}